package ThreadDemo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 阿宾
 * Date: 2025-03-20
 * Time: 15:58
 */
public class ThreadDemo12 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(
                ()->{
                    for (int i = 0; i < 5; i++) {
                        System.out.println("这是一个线程t");
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    System.out.println("线程t执行结束");
                }
        );

        t.start();
        //线程等待
        /*
        在main线程中，调用t.join()；也就是说让main线程等待t线程结束，
        即t线程先执行，main线程后执行
         */
        t.join();
        System.out.println("主线程main，期望是在t线程结束后打印");
    }
}
